﻿Imports System.Reflection

Public Class Mystery

    Private _AssemblyRegister As AssemblyRegister

    Public Event flushRequest()

    Public Sub flushAll()
        Dim registered As IEnumerable(Of Assembly)
        If _AssemblyRegister IsNot Nothing Then
            registered = _AssemblyRegister.getAssemblyRegistered()
        Else
            registered = New List(Of Assembly)
        End If

        _AssemblyRegister = New AssemblyRegister
        For Each ass As Assembly In registered
            _AssemblyRegister.Register(ass)
        Next
        RaiseEvent flushRequest()
    End Sub

    Private Shared _lock As New Object

    Public ReadOnly Property AssemblyRegister As AssemblyRegister
        Get
            If _AssemblyRegister IsNot Nothing Then Return _AssemblyRegister
            SyncLock _lock
                If _AssemblyRegister IsNot Nothing Then Return _AssemblyRegister
                _AssemblyRegister = New AssemblyRegister
            End SyncLock
            Return _AssemblyRegister
        End Get
    End Property

End Class
